import { Pipe, PipeTransform } from '@angular/core';
//定义管道 将电话号码格式化
@Pipe({
  name: 'phone'
})
export class PhonePipe implements PipeTransform {
  transform(val: string): string {
    // tslint:disable-next-line:curly
    if (!val) return '';
    if (val.length === 11) {
      //如果是电话号码使用-分割电话号码
      return val.replace(/(\d{3})(\d{4})(\d{4})/, (m, m1, m2, m3) => {
        return [m1, m2, m3].join('-');
      });
    }
    return val;
  }
}
